package com.neperia.migratore;

import java.util.ArrayList;
import java.util.Iterator;

public class Key {

	public String name;
	public int len_chiave;
	public int[] len_campo;
	public int[] offset;
	public String type;
	public String unique;
	public String[] parent;
	public Parent[] genitori;
	
	public Key(String name, int len_chiave, String type, String unique, String[] parent){
		this.name=name;
		this.len_chiave=len_chiave;
		this.type=type;
		this.unique=unique;
		this.parent=parent;
	}
	
	public String getName(){
		return this.name;
	}
	public int getLen_chiave(){
		return this.len_chiave;
	}
	public int[] getLen_campo(){
		return this.len_campo;
	}
	public int[] getOffset(){
		return this.offset;
	}
	public String getType(){
		return this.type;
	}
	public String getUnique(){
		return this.unique;
	}
	public String[] getParent(){
		return this.parent;
	}
	public Parent[] getGenitori(){
		return this.genitori;
	}
	
	public void setName(String n){
		this.name=n;
	}
	public void setLen_chiave(int k){
		this.len_chiave=k;
	}
	public void setLen_campo(int[] c){
		this.len_campo=c;
	}
	public void setOffset(int[] o){
		this.offset=o;
	}
	public void setType(String t){
		this.type=t;
	}
	public void setUnique(String u){
		this.unique=u;
	}
	public void setGenitori(Parent[] genitori){
		this.genitori=genitori;
	}

	public void setValues(String nameKey, Riga[] db) {
		// TODO Auto-generated method stub
		ArrayList<Integer> c = new ArrayList<Integer>();
		ArrayList<Integer> o = new ArrayList<Integer>();
		for(int i=0;i<db.length;i++){
			if(nameKey.equals(db[i].nome_chiave)){
				c.add(db[i].len_campo);
				o.add(db[i].offset_chiave);
			}
		}
		Iterator<Integer> i_c = c.iterator();
		Iterator<Integer> i_o = o.iterator();
		int[] campo = new int[c.size()];
		int[] off = new int[o.size()];
		int count=0;
		while(i_c.hasNext()){
			campo[count]=i_c.next();
			count++;
		}
		this.setLen_campo(campo);
		count=0;
		while(i_o.hasNext()){
			off[count]=i_o.next();
			count++;
		}
		this.setOffset(off);
		
	}
}
